package com.maila.xiaoaoschool.api;

import android.content.Context;

import com.maila.xiaoaoschool.net.NetWork;
import com.maila.xiaoaoschool.net.VolleyInterface;
import com.maila.xiaoaoschool.util.Constants;

import java.io.File;
import java.util.HashMap;
import java.util.List;

/**
 * Created by mark on 2017/12/7.
 */

public class LoginApi extends NetWork {

    public static final String URL_LOGIN = Constants.URL_ROOT_XIAOAO + "/index.php?ctrl=mapilog"; //版本服务器地址

    public LoginApi(Context ctx, VolleyInterface listener) {
        super(ctx, listener);
    }

    public LoginApi(Context ctx, VolleyInterface listener, String tag) {
        super(ctx, listener, tag);
    }

    /**
     * 用户登录
     *
     * @param username
     * @param pwd
     */
    public void login(String username, String pwd) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("username", username);
        query.put("password", pwd);
        requestPost(URL_LOGIN, "userlogin", query);
    }

    /**
     * 微信登录
     * @param access_token
     * @param openid
     */
    public void  wxlogin(String access_token,String openid){
        HashMap<String, Object> query = new HashMap<>();
        query.put("access_token", access_token);
        query.put("openid", openid);
        requestGet(URL_LOGIN, "wxlogin", query);
    }

    /**
     *qq登录
     * @param openid
     */
    public void  qqlogin(String openid,String username,String logo){
        HashMap<String, Object> query = new HashMap<>();
        query.put("username", username);
        query.put("openid", openid);
        query.put("logo", logo);
        requestGet(URL_LOGIN, "qqlogin", query);
    }



    /**
     * 用户登录
     */
    public void logout() {
        requestGet(URL_LOGIN, "logout");
    }

    /**
     * 添加支付密码
     *
     * @param pwd
     */
    public void set_pay_pwd(String pwd) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("pay_password", pwd);
        requestPost(URL_LOGIN, "pay_password", query);
    }

    /**
     * 获取消息列表
     *
     * @param page
     * @param size
     */
    public void get_message_list(int page, int size) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "message_all", query);
    }

    /**
     * 获取用户信息
     */
    public void getuserinfo() {
        requestGet(URL_LOGIN, "user");
    }

    /**
     * 修改用户信息
     *
     * @param logo
     * @param name
     * @param sex
     * @param age
     * @param phone
     * @param adcode
     */
    public void set_user_info(String logo, String name, String sex, String age, String phone, String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("logo", logo);
        query.put("name", name);
        query.put("sex", sex);
        query.put("age", age);
        query.put("phone", phone);
        query.put("adcode", adcode);
        requestPost(URL_LOGIN, "information", query);
    }

    /**
     * 认证接口
     *
     * @param realname
     * @param xueyuan
     * @param sex
     * @param carid
     * @param just_img
     * @param back_img
     * @param xuehao
     * @param adcode
     */
    public void set_identity(String realname, String xueyuan, String sex, String carid, String just_img, String back_img, String xuehao, String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("realname", realname);
        query.put("xueyuan", xueyuan);
        query.put("xuehao", xuehao);
        query.put("sex", sex);
        query.put("carid", carid);
        query.put("just_img", just_img);
        query.put("back_img", back_img);
        query.put("adcode", adcode);
        requestPost(URL_LOGIN, "information", query);
    }

    /**
     * 收藏商品
     *
     * @param shopid
     * @param goodID
     */
    public void set_collection(String shopid, String goodID) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("shopid", shopid);
        query.put("goodsid", goodID);
        requestPost(URL_LOGIN, "collection", query);
    }

    /**
     * 取消收藏
     *
     * @param goodsid
     */
    public void del_collection(String goodsid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("goodsid", goodsid);
        requestPost(URL_LOGIN, "del_collection", query);
    }

    /**
     * 获取收藏列表
     *
     * @param page
     * @param size
     */
    public void get_collection_list(int page, int size) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "collection_list", query);
    }

    /**
     * 意见反馈
     *
     * @param content
     */
    public void setfeedback(String content) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("content", content);
        requestPost(URL_LOGIN, "feedback", query);
    }

    /**
     * 获取配送地址列表
     *
     * @param page
     * @param size
     */
    public void get_address_list(int page, int size, String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        query.put("adcode", adcode);
        requestGet(URL_LOGIN, "address", query);
    }

    /**
     * 修改默认收货地址
     *
     */
    public void set_default_address(String id) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("oldid", id);
        requestPost(URL_LOGIN, "default_address", query);
    }

    /**
     * 删除收货地址
     *
     * @param addressid
     */
    public void del_address(String addressid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("id", addressid);
        requestPost(URL_LOGIN, "del_address", query);
    }

    /**
     * 新增收货地址
     *
     * @param phone
     * @param name
     * @param adcode
     * @param address
     * @param type    0 新增 1 更新
     */
    public void add_address(String phone, String name, String adcode, String address, int type,String id,String lat,String lng) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("phone", phone);
        query.put("name", name);
        query.put("adcode", adcode);
        query.put("address", address);
        query.put("lat", lat);
        query.put("lng", lng);
        if (type == 0) {
            requestPost(URL_LOGIN, "add_address", query);
        } else {
            query.put("id", id);
            requestPost(URL_LOGIN, "update_address", query);
        }

    }


    /**
     * 获取客服信息
     */
    public void getkefuinfo() {
        requestGet(URL_LOGIN, "kefu");
    }


      /**
     * 上传单张图片
     * @param filepartname
     * @param file
     */
    public  void  uploadimg(String  filepartname, File file){
        uploadOneImg(URL_LOGIN, "update_address", null,filepartname,file);
    }
    /**
     * 上传多张图片
     * @param filepartname
     * @param file
     */
    public  void  uploadmultimg(String  filepartname, List<File> file){
        uploadMutiImg(URL_LOGIN,"update_address", null,filepartname,file);
    }

    /**
     * 获取用户的优惠券列表
     */
    public  void  get_my_coupon_list(){
    requestGet(URL_LOGIN, "quan_list", null);

}

    /**
     * 余额明细
     * @param page
     * @param size
     */
    public  void  get_cost_detail_list(int page,int size){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "cost_detail", query);

    }

    /**
     * 积分明细
     * @param page
     * @param size
     */
    public  void  get_scost_detail_list(int page,int size){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "scost_detail", query);

    }

    /**
     * 加盟入驻
     * @param phone
     * @param name
     * @param school
     * @param role
     */
    public void add_member(String phone, String name, String school,int role) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("phone", phone);
        query.put("name", name);
        query.put("school", school);
        query.put("role", role);
        requestPost(URL_LOGIN, "enter", query);
    }
    /**
     * 全部订单
     * @param page
     * @param size
     */
    public  void  get_all_order_list(int page,int size){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "order_list", query);

    }
    /**
     * 已完成订单
     * @param page
     * @param size
     */
    public  void  get_all_finish_order_list(int page,int size){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "order_list", query);

    }

    /**
     * 未完成订单
     * @param page
     * @param size
     */
    public  void  get_all_no_finish_order_list(int page,int size){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "order_list", query);

    }
    /**
     * 未支付订单
     * @param page
     * @param size
     */
    public  void  get_all_no_pay_order_list(int page,int size){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "order_list", query);

    }
    /**
     * 未评价订单
     * @param page
     * @param size
     */
    public  void  get_all_no_comment_order_list(int page,int size){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "order_list", query);

    }

    /**
     * 发送验证码
     * @param phone
     */
    public  void  send_phone_code(String phone){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("phone", phone);
        requestGet( Constants.URL_ROOT_XIAOAO + "/index.php?ctrl=mapiphone", "send_mobile_code", query);

    }

    /**
     * 注册接口
     * @param password
     * @param phone
     * @param phone_code
     * @param vCode
     */
    public  void  getRegister(String password, String phone, String phone_code, String vCode){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("password", password);
        query.put("phone", phone);
        query.put("phone_code", phone_code);
        query.put("num", vCode);
        requestGet(URL_LOGIN, "register", query);

    }

    /**
     * 重置密码
     * @param password
     * @param phone
     * @param phone_code
     */
    public void  reesetpwd(String password, String phone, String phone_code){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("password", password);
        query.put("phone", phone);
        query.put("phone_code", phone_code);
        requestGet(URL_LOGIN, "revice_password", query);
    }
}
